package com.example.activitytest;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity implements View.OnClickListener, View.OnLongClickListener {

    private EditText et_main_phone;
    private EditText et_main_sms;
    private Button btn_main_call;
    private Button btn_main_send;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        this.et_main_phone=(EditText)findViewById(R.id.et_main_number);
        this.et_main_sms=(EditText)findViewById(R.id.et_main_message);
        this.btn_main_call=(Button)findViewById(R.id.btn_main_phone);
        this.btn_main_call.setOnClickListener(this);
        this.btn_main_call.setOnLongClickListener(this);
        this.btn_main_send=(Button)findViewById(R.id.btn_main_message);
        this.btn_main_send.setOnClickListener(this);
        this.btn_main_send.setOnLongClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.btn_main_phone:
                //点击打电话
                Toast.makeText(this,"点击打电话",Toast.LENGTH_SHORT).show();
                String action = "";
                Intent intent = new Intent(Intent.ACTION_DIAL);
                intent.setData(Uri.parse("tel:"+this.et_main_phone.getText().toString()));
                startActivity(intent);
                break;
            case R.id.btn_main_message:
                Toast.makeText(this,"点击发短信",Toast.LENGTH_SHORT).show();
                break;
        }
    }

    @Override
    public boolean onLongClick(View v) {
        switch (v.getId()){
            case R.id.btn_main_message:
                Toast.makeText(this,"长按打电话",Toast.LENGTH_SHORT).show();
                Intent intent = new Intent(Intent.ACTION_CALL);
                intent.setData(Uri.parse("tel:"+this.et_main_phone.getText().toString()));
                startActivity(intent);
                break;
            case R.id.btn_main_phone:
                Toast.makeText(this,"长按发短信",Toast.LENGTH_SHORT).show();
                break;
        }
        return true;//表示此事件已经被消费了 不会再触发单击事件
    }
}